<script type="text/html" template lay-done="layui.data.sendParams(d);">
    <div class="layui-form coreshop-form layui-form-pane" lay-filter="LAY-app-hotbillboardthrid-editForm" id="LAY-app-hotbillboardthrid-editForm">
        <input type="hidden" name="id" value="{{d.params.data.id || '' }}" />
        <div class="layui-form-item layui-hide">
            <label for="id" class="layui-form-label  layui-form-required">编号</label>
            <div class="layui-input-block">
                <input type="number" min="0" max="999999" name="id" lay-verType="tips" lay-verify="required|number" class="layui-input" value="{{d.params.data.id || '' }}" placeholder="请输入" lay-reqText="请输入并为数字" />
            </div>
        </div>

        <div class="layui-form-item">
            <label for="title" class="layui-form-label  layui-form-required">产品标题</label>
            <div class="layui-input-block">
                <input name="title" lay-verType="tips" lay-verify="required" class="layui-input" placeholder="请输入" lay-reqText="请输入" value="{{d.params.data.title || '' }}" />
            </div>
        </div>

        <div class="layui-form-item">
            <label for="subtitle" class="layui-form-label  layui-form-required">产品卖点</label>
            <div class="layui-input-block">
                <input name="subtitle" lay-verType="tips" lay-verify="required" class="layui-input" placeholder="请输入" lay-reqText="请输入" value="{{d.params.data.subtitle || '' }}" />
            </div>
        </div>

        <div class="layui-form-item">
            <label for="image" class="layui-form-label  layui-form-required">图片</label>
            <div class="layui-input-inline">
                <input name="image" id="imageInput" lay-verType="tips" lay-verify="required" class="layui-input" value="{{d.params.data.image || '' }}" placeholder="请上传" lay-reqText="请上传" />
            </div>
            <div class="layui-input-inline">
                <img class="coreshop-upload-img" id="viewImgBoximage" src="{{d.params.data.image || layui.setter.noImagePicUrl }}">
                <button type="button" class="layui-btn" id="upBtnimage" lay-active="doCropperImg">上传图片</button>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="sales" class="layui-form-label  layui-form-required">销量</label>
            <div class="layui-input-block">
                <input type="number" min="0" max="999999" name="sales" lay-verType="tips" lay-verify="required|number" class="layui-input" value="{{d.params.data.sales || '' }}" placeholder="请输入" lay-reqText="请输入并为数字" />
            </div>
        </div>

        <div class="layui-form-item">
            <label for="sort" class="layui-form-label  layui-form-required">排序</label>
            <div class="layui-input-block">
                <input type="number" min="0" max="999999" name="sort" lay-verType="tips" lay-verify="required|number" class="layui-input" value="{{d.params.data.sort || '' }}" placeholder="请输入" lay-reqText="请输入并为数字" />
            </div>
        </div>

        <div class="layui-form-item layui-hide">
            <label for="boardId" class="layui-form-label  layui-form-required"></label>
            <div class="layui-input-block">
                <input type="number" min="0" max="999999" name="boardId" lay-verType="tips" lay-verify="required|number" class="layui-input" value="{{d.params.data.boardId || '' }}" placeholder="请输入" lay-reqText="请输入并为数字" />
            </div>
        </div>

       

        <div class="layui-form-item">
            <label for="categoryId" class="layui-form-label  layui-form-required">货源分类</label>
            <div class="layui-input-inline layui-inline-6">
                <div id="categoryId_SelectCreateTree" class="ew-xmselect-tree" lay-reqText="请选择商品分类"></div>
            </div>
        </div>


        <div class="layui-form-item text-right core-hidden">
            <input type="button" class="layui-btn" lay-submit lay-filter="LAY-app-hotbillboardthrid-editForm-submit" id="LAY-app-hotbillboardthrid-editForm-submit" value="确认编辑">
        </div>
    </div>
</script>
<script>
    var debug= layui.setter.debug;
    layui.data.sendParams = function (d) {
        //开启调试情况下获取接口赋值数据
        if (debug) { console.log("editdata", d.params.catedata); }
        layui.use(['admin', 'form', 'laydate', 'upload', 'coreHelper', 'cropperImg','xmSelect'],
        function () {
            var $ = layui.$
                , form = layui.form
                , admin = layui.admin
                , laydate = layui.laydate
                , upload = layui.upload
                , cropperImg = layui.cropperImg
                , xmSelect = layui.xmSelect
                , coreHelper = layui.coreHelper;
        
            //图片裁剪上传
            $('#upBtnimage').click(function () {
                cropperImg.cropImg({
                    aspectRatio: 1 / 1,
                    imgSrc: $('#viewImgBoximage').attr('src'),
                    onCrop: function (data) {
                        var loadIndex = layer.load(2);
                        coreHelper.Post("api/Tools/UploadFilesFByBase64", { base64: data }, function (res) {
                            if (0 === res.code) {
                                $('#viewImgBoximage').attr('src', res.data.fileUrl);
                                $("#imageInput").val(res.data.fileUrl);
                                layer.msg(res.msg);
                                layer.close(loadIndex);
                            } else {
                                layer.close(loadIndex);
                                layer.msg(res.msg, { icon: 2, anim: 6 });
                            }
                        });
                    }
                });
            });

            // 渲染商品分类
            var insXmSelGoodsCategoryId = xmSelect.render({
                el: '#categoryId_SelectCreateTree',
                height: '350px',
                data: d.params.catedata.data.categories.data,
                initValue: d.params.data ? [d.params.data.categoryId] : [],
                //initValue: mData ? [mData.parentId] : [],
                //model: { label: { type: 'text' } },
                name: 'categoryId',
                prop: {
                    name: 'title',
                    value: 'id'
                },
                //layVerify: 'verifyGoodsCategory',
                //layVerType: 'msg',
                radio: true,
                clickClose: true,
                tree: {
                    show: true,
                    indent: 15,
                    strict: false,
                    expandedKeys: true
                }
            });

            form.verify({
                
            });
            //重载form
            form.render(null, 'LAY-app-hotbillboardthrid-editForm');
        })
    };
</script>
